package com.srv.control;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class HashControl {
	
	public static String md5(String senha) {
		String pass = "";
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("md5");
			BigInteger hash = new BigInteger(1, md.digest(senha.getBytes()));
			pass = hash.toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		return pass;
	}

	// Função para criar hash da senha informada
	public static String sha1(String senha) {
		String pass = "";
		MessageDigest md = null;
		try {
			md = MessageDigest.getInstance("SHA1");
			BigInteger hash = new BigInteger(1, md.digest(senha.getBytes()));
			pass = hash.toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}

		return pass;
	}
	
	public static void main(String[] args) throws Exception{
		System.out.println(md5("123"));
	}
}
